package cn.lg.soar.message.feign.fallback;

import cn.lg.soar.core.util.InnerSerializeUtils;
import cn.lg.soar.message.api.model.NoticeDTO;
import cn.lg.soar.message.feign.NoticeApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.message.client.NoticeApiClient")
public class NoticeApiFallbackFactory implements FallbackFactory<NoticeApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(NoticeApiFallbackFactory.class);

    @Override
    public NoticeApiFeign create(Throwable cause) {
        return new NoticeApiFeign() {
            @Override
            public void broadcast(NoticeDTO dto) {
                LOGGER.error("broadcast：{}", dto, cause);
            }

            @Override
            public void toUser(NoticeDTO dto, List<Long> userIds) {
                LOGGER.error("toUser：notice={}，userIds={}", InnerSerializeUtils.toJson(dto), InnerSerializeUtils.toJson(userIds));
            }
        };
    }
}
